<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<%
txt_search=trim(SafeRequest("txt_search",0))
call SimpleRecord("cd","null","查询",txt_search,"null",OperateClient("null"),false)
'获取提交查询的参数
sql="select id,cd_company,cd_no,cd_date,cd_voyage,cd_lading,cd_verify,cd_passno,cd_orderno from cd where cd_hidden=false and "


if len(txt_search)=18 and IsNumeric(txt_search) then
    '如果是18位的报关单号，直接查询。用于扫描枪的使用，提高搜索速度
    sql=sql&"cd_no='"&txt_search&"'"
    result_type="cd_no"
elseif len(txt_search)=11  and VerifyContainerCode(txt_search) then
    ' 如果是11位，可能是集装箱号，直接查询集装箱
    sql=sql&"id in (select cd from cdbox where box='"&txt_search&"')"
    result_type="box_no"
else
    sql=sql&"cd_lading='"&txt_search&"'"
    result_type="bill_no"
end if

Function VerifyContainerCode(strCode)
    if not CheckBoxNo(strCode) then Exit Function
    Const Charcode = "0123456789A?BCDEFGHIJK?LMNOPQRSTU?VWXYZ"
    Dim i , n , sum 
     
    If Len(strCode) <> 11 Then Exit Function
     
    For i = 1 To 10
        n = InStr(1, Charcode, UCase(Mid(strCode, i, 1))) - 1
        If n = -1 Or Mid(strCode, i, 1) = "?" Then Exit Function
        n = n * 2 ^ (i - 1)
        sum = sum + n
    Next
    sum = (sum Mod 11) Mod 10
    
     
    If CInt(Mid(strCode, 11, 1)) = sum Then VerifyContainerCode = True
End Function


' response.write sql
'response.end
'执行数据查询
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
If rs.eof Then
%>
<div class="center">
    <h3>没有检索到数据!请输入正确查询条件!<br />
    <%
        set rs_err = Server.CreateObject("ADODB.Recordset")
        sql_err="select top 1 cd_no,cd_lading,box from cd,cdbox where cd.id=cdbox.cd order by cd.id desc"
        rs_err.open sql_err,conn,1,1
        if not rs_err.eof then
    %>
    <table class="center" style="width:520px;border-width:0">
        <tr>
            <td>报关单号，18位数字，例如：</td>
            <td style="text-align:left"><%=rs_err("cd_no")%></td>
        </tr>
        <tr>
            <td>集装箱号，11位箱号，例如：</td>
            <td style="text-align:left"><%=rs_err("box")%></td>
        </tr>
        <tr>
            <td>或提单号，不定位数，例如：</td>
            <td style="text-align:left"><%=rs_err("cd_lading")%></td>
        </tr>
    </table>
    <%
        end if
        rs_err.close
        Set rs_err=nothing
    %>
    </h3>
</div>
<%
else
    select case result_type
        case "cd_no"
            response.write("您输入是18位报关单号，查询结果如下：")
        case "box_no"
            response.write("您输入是11位集装箱号，查询结果如下：")
        case "bill_no"
            response.write("您输入的查询是提单号，查询结果如下：")
    end select
%>
<table class="full">
  <thead>
    <tr>
      <th scope="col">企业名称</th>
      <th scope="col">报关单号</th>
      <th scope="col">申报日期</th>
      <th scope="col">船名/航次</th>
      <th scope="col">提单号</th>
      <th scope="col">核销单号</th>
      <th scope="col">通关单号</th>
      <th scope="col">合同号</th>
    </tr>
  </thead>
  <tbody>
    <%
    do while not rs.eof
    %>
    <tr>
      <td><a target="_blank" href="htmlfile.asp?id=<%=rs("id")%>&dtype=tz&rcd=null"><%=rs("cd_company")%></a></td>
      <td><a target="_blank" href="htmlfile.asp?id=<%=rs("id")%>&rcd=null"><%=rs("cd_no")%></a></td>
      <td><%=rs("cd_date")%></td>
      <td><%=rs("cd_voyage")%></td>
      <td><%=rs("cd_lading")%></td>
      <td><%=rs("cd_verify")%></td>
      <td><%=rs("cd_passno")%></td>
      <td><%=rs("cd_orderno")%></td>
    </tr>
    <%
    rs.movenext
    loop
    %>
    
  </tbody>
</table>
<%
end if
rs.close
Set rs=nothing
%>

<!--#include file="lib/connclose.asp"-->

